<?php
	session_start();
	include_once 'manage_db/db_connect.php';
	include_once 'manage_tags/add_tag_attributes.php';
	include_once 'manage_tags/remove_tag_attributes.php';
	include_once 'forms/edit_tag_form.php';
	include_once 'manage_tags/display_tag_attributes.php';
	include_once 'manage_tags/auto_generate_tags.php';

	$index = $_GET['index'];
	$tag = $_GET['tag'];
	
	include 'html_elements/header.php';
	
	echo "<h1>$tag</h1>";
	$con = db_connect();
	$username = $_SESSION['username'];
	
	
	display_tag_attributes($tag);
	
	for($i=0;$i<$index;$i++){
		print_edit_tag_form($i);
	}
	echo "<input type='submit' value='SUBMIT' name='submit'/></form></p>";
	echo "<a href='edit_tag.php?tag=$tag&index=".($index+1)."'>add field</a><br>";
	echo "<a href='edit_tag.php?tag=$tag&index=".($index-1)."'>remove field</a><br>";
	
	if(isset($_POST['submit'])){
		remove_tag_attributes($tag);
		$attributes;
		$relations;
		$values;
		for($i=0;$i<$index;$i++){
			$attribute = $_POST["attribute$i"];
			$relation = $_POST["relation$i"];
			$value = $_POST["value$i"];
			add_tag_attributes($tag, $attribute, $relation, $value);
			$attributes[$i]=$attribute;
			$relations[$i]=$relation;
			$values[$i]=$value;
		}
		auto_generate_new_tag($tag, $attributes, $relations, $values);	
	}

;?>


<br><a href="manage_tags.php">Go Back</a>
</font>